package com.zls.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zls.mapper.TProducerTypeMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.TProducerType;
import com.zls.pojo.TProducter;
import com.zls.service.TProducerTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TProducerTypeServiceImpl extends ServiceImpl<TProducerTypeMapper, TProducerType> implements TProducerTypeService {
    @Autowired
    private TProducerTypeMapper tProducerTypeMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<TProducerType> page = tProducerTypeMapper.findPage((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = tProducerTypeMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    @Transactional
    public int addType(TProducerType tProducerType) {
        tProducerType.setCreateTime(new Date());
        int insert = tProducerTypeMapper.insertType(tProducerType);
        return insert;
    }
}
